import threading, Queue, random, thread,time
from math import *
# TODO Migrate over all human control functionality to this class
# Functions for...
# World: ForceAgentPosition(agent_num,pos)   ForceAgentHeading(agent_num,heading)
# Game: Add/Remove agent
# Agent Controller: Change active agent, move agent
# This adds functions to the "control_queue" which is a threadsafe queue that will execute the functions passed to it in the main game control loop
# This allows for threadsafe calling of any function in the game's theadsafe region
class human_control(object):
	def __init__(self,tk_root,control_queue,agent_controller,world_model,game_model=None):
		self.tk_root=tk_root
		self.agent_controller=agent_controller
		self.world_model=world_model
		self.game_model=game_model
		self.control_queue=control_queue
		self.tk_root.bind('<Tab>', lambda x:control_queue.put(self.agent_controller.next_agent))
		#self.tk_root.bind('n', agent_controller.new_agent)
		#tk_root.bind('<BackSpace>', main_agent_list.remove_agent)
		self.tk_root.bind('<Up>',lambda x:control_queue.put(self.agent_controller.move_forward))
		self.tk_root.bind('<Down>',lambda x:control_queue.put(self.agent_controller.move_backward))
		self.tk_root.bind('<Right>',lambda x:control_queue.put(self.agent_controller.rotate_cw))
		self.tk_root.bind('<Left>',lambda x:control_queue.put(self.agent_controller.rotate_ccw))
		self.tk_root.bind('<.>',lambda x:control_queue.put(self.agent_controller.strafe_right))
		self.tk_root.bind('<,>',lambda x:control_queue.put(self.agent_controller.strafe_left))
		self.tk_root.bind('<Shift-Up>',lambda x:control_queue.put(self.agent_controller.move_up))
		self.tk_root.bind('<Shift-Down>',lambda x:control_queue.put(self.agent_controller.move_down))
		self.tk_root.bind('<Shift-Right>',lambda x:control_queue.put(self.agent_controller.move_right))
		self.tk_root.bind('<Shift-Left>',lambda x:control_queue.put(self.agent_controller.move_left))
		self.tk_root.bind('s',lambda x:control_queue.put(self.agent_controller.save_log))
		self.tk_root.bind('d',lambda x:control_queue.put(self.agent_controller.dec_man_world_vel))
		self.tk_root.bind('i',lambda x:control_queue.put(self.agent_controller.inc_man_world_vel))
		self.tk_root.bind('t',lambda x:control_queue.put(self.agent_controller.toggle_logging))
